layui.use('form', function () {
    var form = layui.form
        , layer = layui.layer;
});

function changePwd() {

    var oldpwd = jQuery("#oldpwd").val();
    var newpwd = jQuery("#newpwd").val();
    var confirmpwd = jQuery("#confirmpwd").val();
    if (oldpwd.length === 0) {
        layer.tips("请输入旧密码", '#oldpwd', {
            tips: [1, "#0FA6D8"],
            tipsMore: !1,
            time: 2000
        });
        jQuery("#oldpwd").focus();
        return false;
    }
    if (newpwd.length === 0) {
        layer.tips("请输入新密码", '#newpwd', {
            tips: [1, "#0FA6D8"],
            tipsMore: !1,
            time: 2000
        });
        jQuery("#newpwd").focus();
        return false;
    }
    if (confirmpwd.length === 0) {
        layer.tips("请确认新密码", '#confirmpwd', {
            tips: [1, "#0FA6D8"],
            tipsMore: !1,
            time: 2000
        });
        jQuery("#confirmpwd").focus();
        return false;
    }
    if (confirmpwd != newpwd) {
        layer.tips("新密码不一致", '#confirmpwd', {
            tips: [1, "#0FA6D8"],
            tipsMore: !1,
            time: 2000
        });
        jQuery("#confirmpwd").focus();
        return false;
    }


    var changPwd = new Object(); //创建一个存放数据的对象
    changPwd["oldPwd"] = oldpwd;
    changPwd["password"] = newpwd;
    changPwd["confirmpwd"] = confirmpwd;
    var jsoData = JSON.stringify(changPwd); //根据数据生成json数据
    jQuery.ajax({
        url: basePath + "/passwordChange",
        data: jsoData,
        contentType: "application/json;charset=UTF-8", //发送数据的格式
        type: "post",
        dataType: "json", //回调
        beforeSend: function () {
            layer.msg('修改中', {
                icon: 16
                , shade: 0.01
            });
        },
        complete: function () {
            layer.closeAll('loading');
        },
        success: function (data) {
            if (data.status == 200) {
                layer.msg(data.message, {
                    time: 1000,
                    icon: 1,
                    offset: '350px'
                }, function () {
                    location.href = basePath + "/changePwd";//成功登录后转跳的页面
                });
            } else {
                layer.msg(data.message, {
                    time: 1500,
                    icon: 2,
                    offset: '350px'
                });
            }
        }
    });
}